<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
</head>
<body>
<style>
    .layui-form-item .layui-input-company {width: auto;padding-right: 10px;line-height: 38px;}
</style>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layuimini-container layuimini-page-anim" >
            <div class="layuimini-main">
                <form class="layui-form myData" action="save" method="post" lay-filter="stuform" id="save">
                    <input type="hidden" name="id"  id="id"/>

                    <div class="layui-form-item">
                        <label class="layui-form-label">邮箱：</label>
                        <div class="layui-input-block">
                            <input type="text" name="email" lay-verify="email"  id="email" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">学号：</label>
                        <div class="layui-input-block">
                            <input type="text" name="studentNumber" lay-verify="required"  id="studentNumber" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">密码：</label>
                        <div class="layui-input-block">
                            <input type="password" name="password" lay-verify="required"  id="password" class="layui-input" />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="../lib/layui-v2.7.3/layui/layui.js" charset="utf-8"></script>
<script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script src="../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script src="../api/urlConfig.js"></script>
<script>
    // 初始化
    $(function () {
        $.ajax({
            url: ipURL + '/user/get',
            type: 'GET',
            dataType: 'json',
            beforeSend: function (request) {
                request.setRequestHeader("token", localStorage.token);
            },
            success: function (data) {
                $("#id").val(data.data.data.id);
                $("#email").val(data.data.data.email);
                $("#studentNumber").val(data.data.data.studentNumber);
                $("#password").val(data.data.data.password);
            },
        });
    })
    layui.use('form', function(){
        var form = layui.form;

        //提交事件
        form.on('submit(demo1)', function(data){

            $.ajax({
                url: ipURL + '/user/update',
                type: 'post',
                data: JSON.stringify(data.field),
                dataType: 'JSON',
                contentType: 'application/json;charset=UTF-8',
                beforeSend: function (request) {
                    request.setRequestHeader("token", localStorage.token);
                },
                success: function (data) {
                    layer.msg(data.message)
                    $("#id").val(data.data.data.id);
                    $("#email").val(data.data.data.email);
                    $("#password").val(data.data.data.password);
                },
            });

            return false;
        });


    });


</script>
</body>